//
//  oneCheckView.m
//  随便点
//
//  Created by ZC on 15/3/31.
//  Copyright (c) 2015年 qfsoft. All rights reserved.
//

#import "oneCheckView.h"
#import "DropDown2.h"
#import "goodsViewController.h"
#import "AppDelegate.h"

@implementation oneCheckView{
    AppDelegate *delegate;
}



// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    
    delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
    
    [self SZ];
    //定义时间选择器
    UIDatePicker *DatePicker=[[UIDatePicker alloc]initWithFrame:CGRectMake(0, 250, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    DatePicker.datePickerMode=UIDatePickerModeCountDownTimer;
    DatePicker.backgroundColor=[UIColor brownColor];
    [self.superview addSubview:DatePicker];
    self.datePicker=DatePicker;
    [DatePicker addTarget:self action:@selector(DatePickerValueChange:) forControlEvents:UIControlEventValueChanged];
    DatePicker.hidden = YES;
    
    //设置默认时间
//    NSDate *select = [NSDate date];
    NSDate *select = [[NSDate alloc] initWithTimeInterval:60*30 sinceDate:[NSDate date]];
    NSDateFormatter *selectDateFormatter=[[NSDateFormatter alloc]init];
    selectDateFormatter.dateFormat=@"HH:mm";
    NSString *dateAndTime=[selectDateFormatter stringFromDate:select];
    self.timeLabel.text=dateAndTime;
    


}

  //   纯代码创建label
-(void)SetupDishesName:(NSString *)name Price:(NSString *)price Number:(NSString *)number SetY:(int)sety{
    
    //菜名
    UILabel *dishesName = [[UILabel alloc]initWithFrame:CGRectMake(20, sety, 100, 21)];
    dishesName.text = name;
    dishesName.font = [UIFont systemFontOfSize:13];
 
    //价格 和 数量
    UILabel *Price = [[UILabel alloc]initWithFrame:CGRectMake(195, sety, 100, 21)];
    Price.text = [NSString stringWithFormat:@"￥%@  *  %@",price,number];
    Price.font = [UIFont systemFontOfSize:13];
    
    //将“菜名”“价格”“数量”控件添加到view上
    [self.FirstView addSubview:dishesName];
    [self.FirstView addSubview:Price];
}

- (IBAction)SetupButtonClick:(id)sender {
    if (_shezhi.tag==1) {
        [self SZ];
        _shezhi.tag=0;
    }
    else{
        [self WC];
        _shezhi.tag=1;
    }
}

-(void)WC{
    _shezhi.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"wancheng.png"]];
    self.datePicker.hidden=NO;
}
-(void)SZ{
    _shezhi.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"shezhi.png"]];
    self.datePicker.hidden=YES;
}

-(void)DatePickerValueChange:(UIDatePicker *)sender{
    NSDate *select = [sender date];
    NSDateFormatter *selectDateFormatter=[[NSDateFormatter alloc]init];
    selectDateFormatter.dateFormat=@"HH:mm";
    NSString *dateAndTime=[selectDateFormatter stringFromDate:select];
    self.timeLabel.text=dateAndTime;
    
}
-(void)click
{
    self.datePicker.hidden=YES;
}

-(void)setupPayWay:(NSString *)name SetSecondY:(int)setsecondY{
    //创建支付方式
        DropDown2 *dd1 = [[DropDown2 alloc] initWithFrame:CGRectMake(10, setsecondY, 355, 30)];
        NSArray *arr=[[NSArray alloc]initWithObjects:@"货到付款",@"余额支付",@"支付宝支付",@"建设网银支付",nil];
        dd1.tableArray = arr;
        dd1.textField.placeholder=@"支付方式";
        dd1.textField.text =[arr objectAtIndex:0];
        [self.SecondView addSubview:dd1];

}

- (IBAction)dzbutton:(id)sender {
    delegate  = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    [delegate haveView];
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    goodsViewController *dz = [sb instantiateViewControllerWithIdentifier:@"goodsVC"];
    [delegate.haveView pushViewController:dz animated:YES];
    
    
}
- (IBAction)quxiao:(id)sender {
    delegate  = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    [delegate haveView];
    [delegate.haveView popViewControllerAnimated:YES];
    delegate.detailsVC.array=[NSMutableArray array];
}
@end
